package storeMovie.Util;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;

import storeMovie.JavaBean.OrderDetail;

public class OrderDetailManager {

	public OrderDetailManager() {
		
	}
	
	public void saveOrderDetail(OrderDetail orderDetail) {
		Session session = null;
		Transaction t = null;
		try{
			session = HibernateUtil.currentSession();
			t=session.beginTransaction();
			session.save(orderDetail);
			t.commit();
		}catch (Exception ex) {
			ex.printStackTrace();
			t.rollback();
		}
	}
	
	public List<OrderDetail> getOrderDetailByOrderID(int orderId) {
		Session session=null;
		List<OrderDetail> list = null;
		try{
			session = HibernateUtil.currentSession();
			Query query = session.createQuery("from OrderDetail where orderId=?");
			query.setParameter(0, orderId);
			list = query.list();
			return list;
		}catch (Exception ex) {
			ex.printStackTrace();// TODO: handle exception
		}
		return list;
	}
}
